const app = getApp()

import {login} from '../../service/config/index.js'

Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    baseUrl:app.globalData.url,
    //悬浮球相关参数
    ballBottom: 170,
    ballRight: 50,
    ballOpacity: '.8',
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    // orderItems
    orderItems: [    
    ],
  },
  //事件处理函数
  toOrder: function () {
    wx.navigateTo({
      url: '../order/order'
    })
  },
  onLoad: function () {
    
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        withCredentials:true,//非必填  默认为tru
        success: res => {
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    
    }
  },

 
  toLogin: function(e) {
      wx.navigateTo({
        url: '/pages/login/login',
      })
  },

  tx(){
    wx.navigateTo({
      url: '/pages/tx/tx',
    })
  },
  emo(){
    wx.navigateTo({
      url: '/pages/emotion/emotion',
    })
  },
  other(){
    console.log(1)
    wx.navigateTo({
      url: '/pages/about/about',
    })
  },
  toOrder(){
    wx.showToast({
      title: '嘿嘿嘿',
      icon: 'none',
      duration: 2000
    })
  },
  clearCache(){
    this.setData({
      userInfo: '',
      hasUserInfo: false
    })
    wx.clearStorageSync("token")
    wx.clearStorageSync("userInfo")
    wx.clearStorageSync("time")
    wx.showToast({
      title: '缓存已经清理',
      icon: 'none',
      duration: 2000
    })
  },
  onShow(){
    let userInfo = wx.getStorageSync("userInfo");
    this.setData({
      userInfo: userInfo,
      hasUserInfo: true
    })
  }
})
